<template>
    <div class="shop_info">
        <!--    -->
        <van-nav-bar title="申请合伙人" left-arrow fixed @click-left="onClickLeft" :right-text="status==0?'待审批':status==2?'审批不通过':''"/>
        <!-- :readonly="status == 0 || status == 1" -->
        <img v-if="rights_image_url" class="partner_bg" :src="rights_image_url" alt="">
        <van-form :readonly="status == 0" @submit="onSubmit" error-message-align="right" input-align="right">
            <van-field v-model="level_name" name="level_name" label="申请级别" placeholder="请输入申请级别"
                :rules="[{ required: true, message: '请输入申请级别' }]" readonly />
            <van-field v-model="name" name="name" label="姓名" placeholder="请输入姓名"
                :rules="[{ required: true, message: '请输入姓名' }]" />
            <van-field v-model="phone" name="phone" label="联系电话" placeholder="请输入联系电话"
                :rules="[{ required: true, message: '请输入联系电话' }]" />
            <van-field v-model="url" name="url" label="支付凭证:" :border="false" />
            <van-uploader style="margin-left: .32rem;" v-model="card_url" multiple :max-count="1"
                :after-read="afterReadFrontCard" :before-delete="uploadDleteFrontCard" />
            <div class="tip">请点击上传支付截图</div>
            <!--  -->
            <!-- </div> -->
            <div style="margin: 16px;margin-top:.96rem">
                <!--   :disabled="status == 0 || status == 1" -->
                <van-button style="border-radius: 0.44rem;" round block type="info" native-type="submit"
                :disabled="status==0"  color="linear-gradient( 136deg, #6EC069 0%, #42A633 100%)">申请</van-button>
            </div>
        </van-form>

    </div>
</template>
<script>
import { OCR_RECOGNIZE, IDENTITY_INFO, IDENTITY_COMMIT ,PARTNER_APPLY,PARTNER_INFO} from "@/api/mine";
import { getOssParams, uploadImage, uploadDelete, getExampleList } from "@/api/upload";
import { parseTime } from '@/tool/methods'
import { setImageUrl, getImageUrl } from '@/api/upload'; // Adjust the path accordingly
import { Dialog } from 'vant';
export default {
    props: ['settle'],
    data() {
        return {
            name: "",
            phone: "",
            card_url: [],
            status: -1,
            status_desc: "",
            level_name: "合伙人",
            url:'',
            rights_image_url:""
        };
    },
    mounted() {
        window.scrollTo(0, 0)
        //   this.fetchRegions(1, 0);
        this.getInfo()
    },
    methods: {
        onClickLeft() {
            this.$router.go(-1)
        },
        async getInfo() {
            this.$http.get(PARTNER_INFO).then(res=>{
                this.name=res.data.name
                this.phone=res.data.phone
                this.status=res.data.status
                console.log(this.status);
                
                this.card_url = setImageUrl(res.data.voucher_url)
                this.rights_image_url=res.data.rights_image_url
            })
            // this.$http.get(IDENTITY_INFO).then(res => {
            //     this.status = res.data.status
            //     this.status_desc = res.data.status_desc
            //     this.name = res.data.name
            //     this.phone = res.data.phone
            //     this.identity_card_no = res.data.identity_card_no
            //     this.account = res.data.bank_card_no
            //     this.alipay_account = res.data.alipay_account
            //     this.bank_name = res.data.bank_name
            //     this.front_url = setImageUrl(res.data.front_image_url)
            //     this.back_url = setImageUrl(res.data.back_image_url)
            //     this.card_url = setImageUrl(res.data.bank_front_image_url)
            //     // this.handleDialog()
            //     if (res.data.status == 0 && res.data.failure_reason) {
            //         this.handleDialog(res.data)
            //     }
            // })
        },
        handleDialog(res) {
            Dialog.alert({
                title: '失败提示',
                message: res.failure_reason,
                theme: 'round-button',
                confirmButtonColor: '#FF6200'
            }).then(() => {
            });
        },
        // // 上传权益礼包图
        // async afterReadFront(file) {
        //     try {
        //         // 获取OSS上传参数
        //         if (!this.ossParams || this.ossParams.expire_time < Date.now()) {
        //             this.ossParams = await getOssParams(this.$http);
        //         }
        //         if (!this.ossParams) {
        //             throw new Error("OSS参数未正确设置");
        //         }
        //         // 调用封装的上传函数
        //         await uploadImage(file, this.ossParams, this.front_url);
        //     } catch (error) {
        //         console.error("处理上传错误:", error);
        //     }
        // },
        // // 删除权益礼包图
        // uploadDleteFront(file) {
        //     this.front_url = uploadDelete(file, this.front_url);
        // },
        // 上传支付凭证
        async afterReadFrontCard(file) {
            try {
                // 获取OSS上传参数
                if (!this.ossParams || this.ossParams.expire_time < Date.now()) {
                    this.ossParams = await getOssParams(this.$http);
                }
                if (!this.ossParams) {
                    throw new Error("OSS参数未正确设置");
                }
                // 调用封装的上传函数
                await uploadImage(file, this.ossParams, this.card_url);
            } catch (error) {
                console.error("处理上传错误:", error);
            }
        },
        // 删除支付凭证
        uploadDleteFrontCard(file) {
            this.card_url = uploadDelete(file, this.card_url);
            //   this.identity_card = {};
        },
        onSubmit() {
            let params = {
                voucher_url: getImageUrl(this.card_url),
                name: this.name,
                phone: this.phone,
            }
            this.$http.post(PARTNER_APPLY, params).then(res => {
                this.$toast.success('提交成功')
                this.$router.push('/mine')
            })


        }
    },

};
</script>
<style scoped lang="scss">
.shop_info {
    padding-top: 46px;

    ::v-deep .van-nav-bar .van-icon {
        color: #333 !important;
    }

    ::v-deep .van-nav-bar__text {
        color: #333
    }

}

.enterise_info_title {
    font-size: 0.28rem;
    font-weight: bold;
    background: #fff;
    padding: 0.2rem;

    span {
        color: red;
    }
}

.partner_bg {
    display: block;
    width: 95%;
    margin: 0 auto;
    margin-top: .2rem;
    margin-bottom: .32rem;
}

.tianjia_pic {
    // width: 100%;
    display: block;
    width: 100%;
    height: 400px;
    background: #D8D8D8;
    border-radius: .2rem;
}

.tianjia_text {
    width: 100%;
    position: absolute;
    bottom: -20px;
    left: 30%;
    transform: translateX(-50%);
    font-family: PingFangSC, PingFang SC;
    font-weight: 400;
    font-size: 0.24rem;
    color: #999999;
    // line-height: 17px;
    font-style: normal;
}

.tip {
    font-family: PingFangSC, PingFang SC;
    font-weight: 400;
    font-size: .24rem;
    margin-left: .32rem;
    color: #666666;
}
</style>
